package com.zf.shuashua.manager;

import com.vise.xsnow.http.callback.ACallback;
import com.zf.shuashua.api.HttpData;
import com.zf.shuashua.bean.ActionThirdAsk;
import com.zf.shuashua.bean.BaseData;

/**
 * 广告请求/返回/异常-数据上报
 */
public class ActionThirdReportManager {

    private static ActionThirdReportManager instance;

    private ActionThirdReportManager() {

    }

    public static ActionThirdReportManager getInstance() {
        if (null == instance) {
            synchronized (ActionThirdReportManager.class) {
                if (null == instance) {
                    instance = new ActionThirdReportManager();
                }
            }
        }
        return instance;
    }

    /**
     *
     * @param advert_way 广告源，1.穿山甲，2.优量汇，3.百青藤 9.旺翔 10.华为 11.变现猫互动激励
     * @param advert_type 广告类型，1.开屏 2.激励视频 3.信息流 4.贴片 5.全屏视频
     * @param code_bit  代码位
     * @param request_num  请求数量
     */
    public void reportRequestStart(int advert_way, int advert_type, String code_bit, int request_num) {
        ActionThirdAsk report = new ActionThirdAsk();
        report.advert_way = advert_way;
        report.advert_type = advert_type;
        report.code_bit = code_bit;
        report.request_num = request_num;
        report.type = "request_start";
        actionThirdAsk(report);
    }

    public void reportRequestSucc(int advert_way, int advert_type, String code_bit, int return_num) {
        ActionThirdAsk report = new ActionThirdAsk();
        report.advert_way = advert_way;
        report.advert_type = advert_type;
        report.code_bit = code_bit;
        report.return_num = return_num;
        report.type = "request_succ";
        actionThirdAsk(report);
    }

    public void reportRequestFail(int advert_way, int advert_type, String code_bit, int request_num, String error_code, String error_msg) {
        if(request_num < 1){
            request_num = 1;
        }
        ActionThirdAsk report = new ActionThirdAsk();
        report.advert_way = advert_way;
        report.advert_type = advert_type;
        report.code_bit = code_bit;
        report.request_num = request_num;
        report.type = "request_fail";
        report.error_code = error_code;
        report.error_msg = error_msg;
        actionThirdAsk(report);
    }

    public void reportRequestRend(int advert_way, int advert_type, String code_bit, String error_code, String error_msg) {
        ActionThirdAsk report = new ActionThirdAsk();
        report.advert_way = advert_way;
        report.advert_type = advert_type;
        report.code_bit = code_bit;
        report.type = "request_rend";
        report.request_num = 1;
        report.error_code = error_code;
        report.error_msg = error_msg;
        actionThirdAsk(report);
    }

    private void actionThirdAsk(ActionThirdAsk report) {
        HttpData.getInstance().actionThirdAsk(report, new ACallback<BaseData>() {
            @Override
            public void onSuccess(BaseData data) {

            }

            @Override
            public void onFail(int errCode, String errMsg) {
            }
        });
    }

}
